package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.common.result.R;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.vo.BorrowerApprovalVO;
import com.atguigu.srb.core.pojo.vo.BorrowerDetailVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Mr.bilal
 * @since 2023-07-18
 */
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {

    @Autowired
    BorrowerService borrowerService;


    @GetMapping("/getListPage/{limit}/{page}")
    public R getListPage(@PathVariable Long limit,@PathVariable long page ,String keyword){
        IPage<Borrower> borrowerPage = new Page<>();
        borrowerPage.setCurrent(page);
        borrowerPage.setSize(limit);
        borrowerPage =  borrowerService.getListPage(borrowerPage,keyword);
        return R.ok().data("borrowerPage",borrowerPage);
    }

    @GetMapping("/show/{borrowerId}")
    public R show(@PathVariable Long borrowerId){
        BorrowerDetailVO borrower = borrowerService.show(borrowerId);
        return R.ok().data("borrower",borrower);
    }

    @PostMapping("/approvalSubmit")
    public R approvalSubmit(@RequestBody BorrowerApprovalVO borrowerApprovalVO){
        borrowerService.approvalSubmit(borrowerApprovalVO);
        return R.ok();
    }


}

